package com.chenglin.picturepicker.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chenglin.picturepicker.R
import com.chenglin.picturepicker.adapter.TitleAdapter.MyHolder
import com.chenglin.picturepicker.bean.PhotoFileBean
import com.chenglin.picturepicker.databinding.ItemTitleAdapterBinding

class TitleAdapter(var context: Context,var list: List<PhotoFileBean>,var callBack:TitleItemClick) : RecyclerView.Adapter<MyHolder>() {




    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
        var  binding =  ItemTitleAdapterBinding.inflate(LayoutInflater.from(context), parent, false)
      return MyHolder(binding);
    }

    override fun onBindViewHolder(holder: MyHolder, position: Int) {
       var fileName =  when(list[position].fileName){
            "Weixin"->"微信"
            "TmallPic"->"天猫"
            "Camera"->"相机"
            "Screenshots"->"截屏"
            "JDImage"->"京东"
            "meituan"->"美团"
            "Alipay"->"支付宝"
            else->list[position].fileName

        }
        holder.binding.tvTitle.text= "${fileName}(${list[position].number})"
        Glide.with(context).load(list[position].imagePath).error(R.drawable.image_failure).into( holder.binding.ivCamera)
        holder.itemView.setOnClickListener {
            callBack.onItemClickListener(fileName,list[position])
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    class MyHolder(var binding:ItemTitleAdapterBinding) : RecyclerView.ViewHolder(binding.root) {

    }

    interface TitleItemClick{
        fun onItemClickListener(fileName: String,photoFileBean: PhotoFileBean)
    }
}